﻿@model RoadFlow.Model.User
<script type="text/javascript">
    var win = new RoadUI.Window();
    var validate = new RoadUI.Validate();
</script>
<form id="form1" method="post">
    @Html.AntiForgeryToken()
    <br />
    <input type="hidden" name="id" value="@Model.Id" />
    <input type="hidden" name="password" value="@Model.Password" />
    <input type="hidden" name="headImg" value="@Model.HeadImg" />
    <table cellpadding="0" cellspacing="1" border="0" width="95%" class="formtable">
        <tr>
            <th style="width:120px;">姓名：</th>
            <td><input type="text" name="Name" class="mytext" onchange="getPy(this.value);" value="@Model.Name" validate="empty,min,max" max="50" style="width:260px;" /></td>
        </tr>
        <tr>
            <th>帐号：</th>
            <td><input type="text" id="Account" name="Account" class="mytext" value="@Model.Account" validate="empty,max,ajax" validate_url="CheckAccount?id=@Model.Id" max="20" style="width:260px;" /></td>
        </tr>
        <tr>
            <th>性别：</th>
            <td>
                <input type="radio" validate="radio" @(Model.Sex == 0 ? "checked='checked'" : "") value="0" name="Sex" id="Sex_0" style="vertical-align:middle;" /><label for="Sex_0" style="vertical-align:middle;">男</label>
                <input type="radio" validate="radio" @(Model.Sex == 1 ? "checked='checked'" : "") value="1" name="Sex" id="Sex_1" style="vertical-align:middle;" /><label for="Sex_1" style="vertical-align:middle;">女</label>
                <span class="validate"></span>
            </td>
        </tr>
        <tr>
            <th>状态：</th>
            <td>
                <input type="radio" validate="radio" @(Model.Status == 0 ? "checked='checked'" : "") value="0" name="Status" id="Status_0" style="vertical-align:middle;" /><label for="Status_0" style="vertical-align:middle;">正常</label>
                <input type="radio" validate="radio" @(Model.Status == 1 ? "checked='checked'" : "") value="1" name="Status" id="Status_1" style="vertical-align:middle;" /><label for="Status_1" style="vertical-align:middle;">冻结</label>
                <span class="validate"></span>
            </td>
        </tr>
        <tr>
            <th>所在组织：</th>
            <td>@Html.Raw(ViewData["organizes"])</td>
        </tr>
        <tr>
            <th>所在工作组：</th>
            <td>@Html.Raw(ViewData["workgroups"])</td>
        </tr>

        <tr id="StationMove_tr" style="display:none;">
            <th style="width:80px;">调往组织：</th>
            <td>
                <table cellpadding="0" cellspacing="1" border="0">
                    <tr>
                        <td>
                            <input type="text" style="width:180px;" title="选择要调往的组织：" class="mymember" id="movetostation" name="movetostation" more="false" user="false" station="true" dept="true" unit="true" />
                            <input type="checkbox" name="movetostationjz" id="movetostationjz" style="vertical-align:middle;" value="1" /><label for="movetostationjz" style="vertical-align:middle;">兼任</label>
                        </td>
                        <td><input type="button" class="mybutton" name="Move1" onclick="return stationMove1(this);" value="确定调动" /></td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
    <div style="width:95%; margin:8px auto; text-align:center;">
        联系信息：
    </div>
    <table cellpadding="0" cellspacing="1" border="0" width="95%" class="formtable">
        <tr>
            <th style="width:120px;">手机：</th>
            <td><input type="text" name="Mobile" class="mytext" value="@Model.Mobile" style="width:70%;" /></td>
            <th style="width:120px;">办公电话：</th>
            <td><input type="text" name="Tel" class="mytext" value="@Model.Tel" style="width:70%;" /></td>
        </tr>
        <tr>
            <th>微信号：</th>
            <td><input type="text" name="WeiXin" class="mytext" value="@Model.WeiXin" style="width:70%;" /></td>
            <th>邮箱：</th>
            <td><input type="text" name="Email" class="mytext" value="@Model.Email" validate="canempty,email" style="width:70%;" /></td>
        </tr>
        <tr>
            <th>传真：</th>
            <td><input type="text" name="Fax" class="mytext" value="@Model.Fax" style="width:70%;" /></td>
            <th>QQ：</th>
            <td><input type="text" name="QQ" class="mytext" value="@Model.QQ" style="width:70%;" /></td>
        </tr>
        <tr>
            <th>其它联系方式：</th>
            <td colspan="3"><input type="text" name="OtherTel" value="@Model.OtherTel" class="mytext" style="width:98%;" /></td>
        </tr>
        <tr>
            <th style="width:120px;">备注：</th>
            <td colspan="3"><textarea name="Note" class="mytext" style="width:98%; height:50px;">@Model.Note</textarea></td>
        </tr>
    </table>
    <div style="width:95%; margin:10px auto 10px auto; text-align:center;">
        @if (!"1".Equals(ViewData["isAddUser"]))
        {
            <input type="button" class="mybutton" value="设置菜单" onclick="setMenu();" />
            <input type="button" class="mybutton" value="查看已分配菜单" onclick="showMenu();" />
            <input type="button" value="&nbsp;调&nbsp;&nbsp;动&nbsp;" class="mybutton" onclick="stationMove();" />
            <input type="button" class="mybutton" value="&nbsp;排&nbsp;&nbsp;序&nbsp;" onclick="sort1('@ViewData["parentId"]');" />
            <input type="button" class="mybutton" onclick="initPassword(this)" value="初始密码" />
        }
        <input type="button" class="mybutton" onclick="saveUser(this);" value="&nbsp;保&nbsp;&nbsp;存&nbsp;" />
        @if ("1".Equals(ViewData["isAddUser"]))
        {
            <input type="button" class="mybutton" onclick="window.location='@Html.Raw(ViewData["returnUrl"])';" name="Save" value="&nbsp;返&nbsp;&nbsp;回&nbsp;" />
        }
        @if (!"1".Equals(ViewData["isAddUser"]))
        {
            <input type="button" class="mybutton" onclick="deleteUser(this);" value="&nbsp;删&nbsp;&nbsp;除&nbsp;" />
        }
    </div>
</form>
<script type="text/javascript">
    function getPy(v) {
        if ($.trim($('#Account').val()).length > 0) {
            return;
        }
        $.ajax({
            url: 'GetAccountByName@(Html.Raw(ViewData["queryString"]))',
            data: { 'name': v },
            dataType: 'text',
            type: 'post',
            cache: false,
            success: function (txt) {
                $('#Account').val(txt);
            }
        });
    }
    function saveUser(but) {
        var f = document.forms[0];
        if (validate.validateForm(f)) {
            $(but).prop("disabled", true);
            var o = RoadUI.Core.serializeForm($(f));
            $.ajax({
                url: "SaveUser@(Html.Raw(ViewData["queryString"]))", data: o, type: "post", success: function (text) {
                    if (RoadUI.Core.checkLogin(text, false)) {
                        alert(text);
                    }
                    $(but).prop("disabled", false);
                    if (text.indexOf("保存成功") >= 0) {
                        parent.frames[0].reLoad('@ViewData["refreshId"]');
                        window.location = window.location;
                    }
                }
            });
        }
    }
    function deleteUser(but) {
        if (!confirm('您真的要删除该人员吗?')) {
            return;
        }
        $(but).prop("disabled", true);
        $.ajax({
            url: "DeleteUser@(Html.Raw(ViewData["queryString"]))", data: { "__RequestVerificationToken": $("input[name='__RequestVerificationToken']").val() }, type: "post", success: function (text) {
                if (RoadUI.Core.checkLogin(text, false)) {
                    alert(text);
                }
                $(but).prop("disabled", false);
                parent.frames[0].reLoad('@ViewData["refreshId"]');
                window.location = "Empty"
            }
        });
    }
    function initPassword(but) {
        if (!confirm('您真的要初始化密码吗?')) {
            return;
        }
        $(but).prop("disabled", true);
        $.ajax({
            url: "InitUserPassword@(Html.Raw(ViewData["queryString"]))", data: { "__RequestVerificationToken": $("input[name='__RequestVerificationToken']").val() }, type: "post", success: function (text) {
                $(but).prop("disabled", false);
                if (RoadUI.Core.checkLogin(text, false)) {
                    alert(text);
                }
            }
        });
    }
    function stationMove() {
        $('#StationMove_tr').toggle();
    }
    function stationMove1(but) {
        var toOrgId = $.trim($("#movetostation").val());
        if (toOrgId.length == 0) {
            alert("请选择要调往的组织!");
            return false;
        }
        var isjz = $("#movetostationjz").prop("checked") ? "1" : "0";
        $(but).prop("disabled", true);
        $.ajax({
            url: "MoveUser@(Html.Raw(ViewData["queryString"]))", data: { "toOrgId": toOrgId, "isjz": isjz, "__RequestVerificationToken": $("input[name='__RequestVerificationToken']").val() }, type: "post", success: function (text) {
                if (RoadUI.Core.checkLogin(text, false)) {
                    alert(text);
                }
                $(but).prop("disabled", false);
                parent.frames[0].reLoad(toOrgId);
                parent.frames[0].reLoad('@ViewData["refreshId"]');
            }
        });
    }

    function sort1() {
        window.location = 'UserSort@(Html.Raw(ViewData["queryString"]))';
    }

    function setMenu() {
        var url = "SetMenu@(Html.Raw(ViewData["queryString"]))&prevurl=@Html.Raw(ViewData["prevUrl"])";
        window.location = url;
        return false;
    }

    function showMenu() {
        var url = "ShowUserMenu?@(Html.Raw(ViewData["prevUrl"]))";
        window.location = url;
        return false;
    }
</script>